//
//  AY_BookSelfCell.m
//  AiYue
//
//  Created by mac on 2023/10/16.
//

#import "AY_BookSelfCell.h"

@interface AY_BookSelfCell()

/** 书 */
@property (strong,nonatomic) UIImageView *bookImage;

/** 书名 */
@property (strong,nonatomic) UILabel *bookName;

/** 书名 */
@property (strong,nonatomic) UILabel *desLabel;
@property (strong,nonatomic) UILabel *tipLabel;
@end

@implementation AY_BookSelfCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.bookImage = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.contentView];
        [self.bookImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(YNUM(120));
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(YNUM(15));
        }];
        
        self.tipLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(10) andLines:1 andRadius:0 andAddSubView:self.bookImage];
        self.tipLabel.layer.masksToBounds = NO;
        self.tipLabel.textAlignment = NSTextAlignmentCenter;
        [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.equalTo(self.bookImage);
            make.width.mas_equalTo(YNUM(28));
            make.height.mas_equalTo(YNUM(16));
        }];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(28), YNUM(16)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(YNUM(4), YNUM(4))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.tipLabel.bounds;
        maskLayer.path = maskPath.CGPath;
        self.tipLabel.layer.mask = maskLayer;
        
        self.bookName = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(14)] andLines:2 andRadius:0 andAddSubView:self.contentView];
        [self.bookName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bookImage.mas_bottom).offset(YNUM(5));
            make.left.equalTo(self.bookImage);
            make.right.equalTo(self.contentView);
        }];
        
        self.desLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#97A4B0") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
        [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.bookName);
            make.bottom.equalTo(self.contentView);
        }];
    }
    return self;
}

- (void)sendBookSelfModel:(BookSelfModel *)model andIsLast:(BOOL)isLast {
    if (isLast) {
        self.bookImage.image = YImage(@"AY_book_add");
        self.bookName.hidden = YES;
        self.desLabel.hidden = YES;
        self.tipLabel.hidden = YES;
    }else {
        self.bookName.hidden = NO;
        self.desLabel.hidden = NO;
        self.bookName.text = model.articleTitle;
        self.desLabel.text = model.chapterNo.integerValue <= 0 ? [NSString stringWithFormat:@"1章/%@章",model.chapterCount] : [NSString stringWithFormat:@"%@章/%@章",model.chapterNo,model.chapterCount];
        [self.bookImage sd_setImageWithURL:[NSURL URLWithString:model.articleCoverImg] placeholderImage:YImage(@"placeholderImage")];
        self.tipLabel.hidden = NO;
    }
    if ([model.hasNewChapter isEqual:@"1"]) {
        self.tipLabel.text = @"更新";
        self.tipLabel.backgroundColor = THEME_COLOR;
    }else {
        self.tipLabel.backgroundColor = COLOR(@"8a8d96");
        if ([model.articleStatus isEqual:@"1"]) {
            self.tipLabel.text = @"连载";
        }else if ([model.articleStatus isEqual:@"3"]) {
            self.tipLabel.text = @"停更";
        }else {
            self.tipLabel.text = @"完结";
        }
    }
}
@end
